var arrReader = "";// 存储读头信息
function getParent() {
	var reader = $("readerType");
	var readDiv = $("readers");
	var readerID = reader.options[reader.selectedIndex].value;
	var readerName = reader.options[reader.selectedIndex].text;
	if (checkReader(readerID, readerName)) {
		var span = document.createElement("span");
		span.setAttribute("id", "span" + readerID);
		readDiv.appendChild(span);
		span.className = "addSp";
		var spanID = "span" + readerID;
		span.innerHTML = "<input type='text' value='"
				+ readerName
				+ "' class='selInput' readonly=''/><img src='/SCMDB/images/del.gif' class='delImg' onclick='delParent(\""
				+ spanID + "\",\"" + readerID + "\")' title='Remove the' />";
		if (arrReader == "") {
			arrReader = readerID;
		} else {
			arrReader = arrReader + "," + readerID;
		}
		$("readerID").value = arrReader;
	}
}
window.onload = function() {
	var readDiv = $("readers");
	var readers = $("readerID").value;
	var arr = readers.split(",");
	var reader = $("readerType");
	var ops = reader.options;
	for ( var read = 0; read < arr.length; read++) {
		for ( var i = 0; i < ops.length; i++) {
			if (arr[read] == ops[i].value) {
				if (checkReader(ops[i].value, ops[i].text)) {
					var span = document.createElement("span");
					span.setAttribute("id", "span" + ops[i].value);
					readDiv.appendChild(span);
					span.className = "addSp";
					var spanID = "span" + ops[i].value;
					span.innerHTML = "<input type='text' value='"
							+ ops[i].text
							+ "' class='selInput' readonly=''/><img src='/SCMDB/images/del.gif' class='delImg' onclick='delParent(\""
							+ spanID + "\",\"" + ops[i].value + "\")' title='Remove the' />";
					if (arrReader == "") {
						arrReader = ops[i].value;
					} else {
						arrReader = arrReader + "," + ops[i].value;
					}
					$("readerID").value = arrReader;
				}
			}
		}
	}
}
function checkReader(readerID, readerName) {
	var readers = arrReader.split(",");
	for ( var i = 0; i < readers.length; i += 1) {
		if (readerID == readers[i]) {
			popupCount = 1;
			Super.Popup (2, "警告", "", readerName + "号读头已经添加！");
			return false;
		}
	}
	return true;
}
function delReader(readerID) {
	var readers = arrReader.split(",");
	var lastReader = "";
	for ( var i = 0; i < readers.length; i += 1) {
		if (readerID != readers[i]) {
			if (lastReader == "") {
				lastReader = readers[i];
			} else {
				lastReader = lastReader + "," + readers[i];
			}
		}
	}
	arrReader = lastReader;
	$("readerID").value = arrReader;
}
function delParent(spanID, readerID) {
	$("readers").removeChild($(spanID));
	delReader(readerID);
}